﻿
using System;

using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 输出参数
    /// </summary>
    public class OutPutParameter:ViewModelBase
    {
        /// <summary>
        /// 输出参数
        /// </summary>
        /// <param name="source"></param>
        /// <param name="name"></param>
        /// <param name="propertyName"></param>
        public OutPutParameter(FilterBase source, string name, string propertyName, Type type)
        {
            Source = source;
            Name = name;
            PropertyName = propertyName;
            source.PropertyChanged += Source_PropertyChanged;
            Type = type;
        }

        private void Source_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName==PropertyName)
            {
                RaisedPropertyChanged(nameof(Value));
            }
        }
        public Type Type { get; set; }
        /// <summary>
        /// 源
        /// </summary>
        public FilterBase Source { get; set; }
        /// <summary>
        /// 属性名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 属性名称
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        /// 属性值
        /// </summary>
        public object Value
        {
            get => Source.GetValue(PropertyName);
            set => Source.SetValue(PropertyName, value);
        }
    }
    /// <summary>
    /// 输入参数
    /// </summary>
    public class InputParameter
    {
        public InputParameter(FilterBase source, object value, string name, string propertyName, ParameterType isMust, Type type)
        {
            Source = source;
            PropertyName = propertyName;
            Value = value;
            Name = name;
            IsMust = isMust;
            Type = type;
        }
        public Type Type { get; set; }
        /// <summary>
        /// 源
        /// </summary>
        public FilterBase Source { get; set; }
        /// <summary>
        /// 属性值
        /// </summary>
        public object Value 
        {
            get => Source.GetValue(PropertyName);
            set=>Source.SetValue(PropertyName, value);
        }
        public object[] Values
        {
            get
            {
                if (Type==typeof(bool))
                {
                    return new object[] { true,false};
                }
               return  Source.GetEnumValues(PropertyName);
            }
        }
        /// <summary>
        /// 属性名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 属性名称
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        ///是否必选参数
        /// </summary>
        public ParameterType IsMust { get; set; }
    }

}
